package com.atguigu.gulimall.search.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadTezt {



    public static void main(String[] args)
            throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newFixedThreadPool(10);

//         CompletableFuture.runAsync(() -> {
//            System.out.println("当前线程：" + Thread.currentThread().getId());
//            System.out.println("运算结果：" + 3);
//        },executor);

        System.out.println("1111111");

        CompletableFuture<Integer> future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务1线程：" + Thread.currentThread().getId());
            System.out.println("任务1结束：" );
            return 3;
        },executor);

        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务2线程：" + Thread.currentThread().getId());
            System.out.println("任务2结束：" );
            return "hello";
        },executor);

      //  System.out.println(future1.get());
//        future1.runAfterBothAsync(future2,()->{
//          System.out.println("任务3");
//      });

//        future1.thenAcceptBothAsync(future2,(f1,f2)->{
//            System.out.println(f1+" "+f2);
//        },executor);


        CompletableFuture<String> future3 = future1.thenCombineAsync(future2, (f1, f2) -> {
            System.out.println(f1 + " " + f2);
            return f1 + "" + f2;
        }, executor);


        System.out.println(future3.get());
        System.out.println("11111");


    }
}
